package com.binary.coder.gift.core.domain.ai.impl;

import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.server.HttpServerRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.binary.coder.gift.core.domain.ai.factory.XingHuoFactory;
import com.binary.coder.gift.core.domain.ai.model.XingHuoModelInputParam;
import com.binary.coder.gift.core.domain.ai.model.XingHuoModeloutputParam;
import lombok.extern.slf4j.Slf4j;

/**
 * @author atao
 * @version 1.0.0
 * @ClassName AbstractXingHuoClient.java
 * @Description 星火大模型抽象客户端
 * @createTime 2024年07月12日 10:08:00
 */
@Slf4j
public abstract class AbstractXingHuoClient {

    protected String xinghuo_secretId;
    protected String xingghuo_secretKey;

    public AbstractXingHuoClient(String xinghuo_secretId, String xingghuo_secretKey) {
        this.xinghuo_secretId = xinghuo_secretId;
        this.xingghuo_secretKey = xingghuo_secretKey;
    }

    XingHuoModeloutputParam ChatCompletions(String message){
        XingHuoModelInputParam xingHuoModelInputParam = XingHuoFactory.buildXingHuoModelInputParam(message);
        HttpResponse response = HttpRequest.post("https://spark-api-open.xf-yun.com/v1/chat/completions")
                .contentType("application/json")
                .header("Authorization", "Bearer " + xingghuo_secretKey + ":" + xinghuo_secretId)
                .body(JSON.toJSONString(xingHuoModelInputParam))
                .execute();
        return XingHuoFactory.buildXingHuoModeloutputParam(response.body());
    }

}
